package Operation;

import Book.Book;
import Book.Bookshelf;

import java.util.Scanner;

public class DeleteBook implements IOperation {
    @Override
    public void working(Bookshelf bookshelf) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入您所想要删除的图书的名字：");
        String bookName = scanner.nextLine();

        int pos = -1;
        for (int i = 0; i < bookshelf.bookShelfNumber; i++) {
            Book book = bookshelf.books[i];
            if (bookName.equals(book.getName())) {
                pos = i;
                break;
            }
        }

        if (pos == -1) {
            System.out.println("对不起，书架上没有该图书！！！");
            return;
        }

        for (int k = pos; k < bookshelf.books.length - 1; k++) {
            bookshelf.books[k] = bookshelf.books[k + 1];
        }
        bookshelf.bookShelfNumber--;

        System.out.println("图书删除成功...");
    }
}
